//
//  APIManager.h
//  OCStarterProject
//
//  Created by huaya on 2025/10/2.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "APIResponse.h"

NS_ASSUME_NONNULL_BEGIN

// 请求成功回调
typedef void (^RequestSuccessHandler)(BOOL success, id _Nullable responseData, APIResponse* requestModel);

// 快速请求成功回调（包含缓存标识）
typedef void (^QuickRequestSuccessHandler)(BOOL success, id _Nullable responseData, BOOL isFromCache, APIResponse* requestModel);

// 请求失败回调
typedef void (^RequestFailureHandler)(NSURLSessionDataTask * _Nullable task, NSError *error);

@interface APIManager : NSObject

#pragma mark - 单例方法
+ (instancetype)sharedInstance;

#pragma mark - POST请求方法
/// 标准POST请求
+ (NSURLSessionDataTask *)sendPostRequest:(NSString *)url
                               parameters:(NSDictionary * _Nullable)params
                                    model:(Class _Nullable)modelClass
                                  success:(RequestSuccessHandler)successBlock
                                  failure:(RequestFailureHandler)failureBlock;

/// 快速POST请求（支持缓存）
+ (NSURLSessionDataTask *)sendQuickPostRequest:(NSString *)url
                                    parameters:(NSDictionary * _Nullable)params
                                         model:(Class _Nullable)modelClass
                                       success:(QuickRequestSuccessHandler)successBlock
                                       failure:(RequestFailureHandler)failureBlock;

/// 自定义队列的POST请求
+ (NSURLSessionDataTask *)sendPostRequest:(NSString *)url
                               parameters:(NSDictionary * _Nullable)params
                                    model:(Class _Nullable)modelClass
                          completionQueue:(dispatch_queue_t)queue
                                  success:(RequestSuccessHandler)successBlock
                                  failure:(RequestFailureHandler)failureBlock;

#pragma mark - GET请求方法
/// 标准GET请求
+ (NSURLSessionDataTask *)sendGetRequest:(NSString *)url
                              parameters:(NSDictionary * _Nullable)params
                                   model:(Class _Nullable)modelClass
                                 success:(RequestSuccessHandler)successBlock
                                 failure:(RequestFailureHandler)failureBlock;

/// 自定义队列的GET请求
+ (NSURLSessionDataTask *)sendGetRequest:(NSString *)url
                              parameters:(NSDictionary * _Nullable)params
                                   model:(Class _Nullable)modelClass
                         completionQueue:(dispatch_queue_t)queue
                                 success:(RequestSuccessHandler)successBlock
                                 failure:(RequestFailureHandler)failureBlock;

#pragma mark - 工具方法
/// 取消所有网络请求
+ (void)cancelAllNetworkRequests;

/// 设置请求头信息
+ (void)setRequestHeaderValue:(NSString *)value forField:(NSString *)field;

/// 检查网络连接状态
+ (BOOL)isNetworkAvailable;

@end

NS_ASSUME_NONNULL_END
